from src.db import dbm, dbs
from sqlalchemy.orm import scoped_session
from flask_jwt_extended import jwt_required
from src.core.variables.status import SUCCESS_CODE
from src.api.origin import admin_permission, capture_exception


@capture_exception
@jwt_required()
@admin_permission
# @refresh_token_on_request
def all_nodes(user):
    """返回所有已经绑定主节点的"""
    result = []
    with dbm.get("sys_default") as db_session:
        db_session: scoped_session
        db_result = db_session.query(dbs.sys_default.Node).all()
        for i in db_result:
            result.append(i.ip)
        return SUCCESS_CODE.DATA_FETCHED(str(result))
